package com.raft.framework.base

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

open class RFBaseFragment : Fragment(){


    protected fun <T: ViewModel> provideViewModel(modelClass:Class<T>):T{
        return ViewModelProviders.of(this).get(modelClass)
    }

    protected fun <T: ViewModel> provideViewModelFromActivity(modelClass:Class<T>):T{
        return ViewModelProviders.of(activity!!).get(modelClass)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (getContentLayoutId() != 0){
            return inflater.inflate(getContentLayoutId(),container,false)
        }
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    open protected fun getContentLayoutId() : Int = 0


    fun finish() {

        activity?.finish()

    }

    fun isFinish(): Boolean {
        return activity?.isFinishing == true
    }

    open fun getPageTitle():String?=null

}